extends KinematicBody2D

export var max_speed = 500.0
var _velocity = Vector2.ZERO

const MIN_DISTANCE = 3.0 # 最小距离

onready var sprite = $player


func _physics_process(delta):
	var target_global_position: Vector2  = get_global_mouse_position()
	
	# 角色与目标位置之间的距离小于规定的最小距离
	if global_position.distance_to(target_global_position) < MIN_DISTANCE:
		return
	
	_velocity = Steering.fllow(
		_velocity,
		global_position,
		target_global_position,
		max_speed
	)
	
	_velocity = move_and_slide(_velocity)
	# 角色转向
	sprite.rotation = _velocity.angle()
